Ext.define('App.main.view.MainNavbar', {
    extend: 'Extend.navbar.Navbar',
    alias: ['widget.MainNavbar'],
    height: 66,
    backgroundColor: '#444',
    itemWidth: '100px',
    menus: [
        {
            icon: 'css/icons/logo.png',
            logo: true,
            href: '/',
            style: {
                width: '128px',
                marginLeft: '5px',
                marginRight: '10px'
            }
        },
        {
            name: '项目度量',
            style: {
                width: '100px'
            },
            actived: true
        },
        {
            name: '版本度量'
        },
        {
            name: '版本信息'
        },
        {
            name: '人力信息'
        },
        {
            name: '项目信息'
        }
    ], listeners: {
        afterrender: function () {
            this.createLeftButtons();
        }
    },
    createLeftButtons: function () {
        var spec = {
            id: 'buttons-ul',
            tag: 'ul',
            cls: 'buttons-ul',
            // append children after creating
            children: [
                {
                    tag: 'li', cls: 'po-config', title: '项目订单',
                    children: [
                        {tag: 'a', cls: 'icon', href: "?po", target: "_blank"},
                        {tag: 'span', html: '项目订单'}
                    ]
                },
                {
                    tag: 'li', cls: 'qa-config', title: '项目质量',
                    children: [
                        {tag: 'a', cls: 'icon', href: "?qa", target: "_blank"},
                        {tag: 'span', html: '项目质量'}
                    ]
                },
                {
                    tag: 'li', cls: 'pm-config', title: '项目管理',
                    children: [
                        {tag: 'a', cls: 'icon', href: "?pm", target: "_blank"},
                        {tag: 'span', html: '项目管理'}
                    ]
                },
                {
                    tag: 'li', cls: 'admin-config', title: '系统配置',
                    children: [
                        {tag: 'a', cls: 'icon', href: "?administrator", target: "_blank"},
                        {tag: 'span', html: '系统配置'}
                    ]
                },
                {
                    tag: 'li', cls: 'userinfo', title: '帐号',
                    children: [
                        {tag: 'a', cls: 'icon', href: "jacript:vvasoid(0)"},
                        {tag: 'span', html: '帐号'}
                    ]
                },
                {
                    tag: 'li', cls: 'logout', title: '注销',
                    children: [
                        {tag: 'a', cls: 'icon', href: "jacript:vvasoid(0)"},
                        {tag: 'span', html: '注销'}
                    ]
                }
            ]
        };
        var buttons = Ext.dom.Helper.append(
            this.body, // the context element 'my-div' can either be the id or the actual node
            spec,
            true    // the specification object
        )

        var btnUserinfo = buttons.query('.userinfo a', false)[0]
        btnUserinfo.on({
            click: function () {
                var user = app.user;
                Ext.create('App.authorization.user.view.CurrentUserinfoEditor', {
                    model: 'App.authorization.user.UserModel',
                    url: 'authorization/user/update_current_userinfo', listeners: {
                        save: function (form, action) {
                            if (action.result.success == true) {
                                app.user = action.result.data;
                            }
                        }
                    }
                }).show().load({
                    url: 'authorization/user/get_by_username',
                    params: {
                        username: user.username
                    }
                });
            }
        });
        var btnLogout = buttons.query('.logout a', false)[0]
        btnLogout.on({
            click: function () {
                Ext.Ajax.request({
                    url: 'logout',
                    success: function (resp) {
                        if (resp.result.success == true) {
                            app.showLoginWindow();
                        } else {
                            Extend.Msg.error('错误', resp.result.result, resp.result.messages, resp.result.errors, resp.result.exceptions)
                        }
                    }
                });
            }
        });
    }

})